﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using WLFramework.DataAccess;
using WLFramework.Json;
using WLFramework.Validation;
using WLFramework.Web;

namespace SampleSite.admin.ajax
{
    /// <summary>
    /// getRoleByPosition 的摘要说明
    /// </summary>
    public class getRoleByPosition : IHttpHandler
    {
        private class InputData
        {
            [Required]
            public int P_ID { get; set; }
        }

        public void ProcessRequest(HttpContext context)
        {
            InputData input;
            var errors = context.GetModel<InputData>(out input);
            if (errors.Count > 0)
            {
                throw new Exception("输入的数据格式不正确");
            }

            using (PermissionContext db = new PermissionContext())
            {
                var cmd = DataAccessor.CreateInstance<PermissionCommand>(db);
                var modules = cmd.GetRoleByPosition(input.P_ID);

                context.Response.Write(JSON.Instance.ToJSON(modules));
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}